
//#include "Reactor.hpp"
#include "calcualtor.hpp"
#include "Expressed.hpp"
#include "ReactorConcurrent.hpp"

void stop(ReactorConcurrent& reactorc)
{
    sleep(10);
    reactorc.Stop();
}


int main(int argc, char *argv[])
{
    if (argc != 3)
    {
        cout << "use: ./ServerMain server_port thread_num" << endl;
        return 1;
    }
    uint16_t port = stoi(argv[1]);

    int thread_num=stoi(argv[2]);
    if(thread_num<=0)
    {
        cout << "thread_num必须大于0" << endl;
        return 2;
    }

    ReactorConcurrent reactorc(port,thread_num);//会话层

    Calculator cal;//计算器--应用层

    Expressed expressed;//表示层


    expressed.Registration([&cal](const int left,const char oper,const int right,int& result)
    {
        return cal.Calculate(left,oper,right,result);
    });

    reactorc.Registered([&expressed](string &readbuff)
    {
        return expressed.HandleRequest(readbuff);
    });

    
    //thread t(stop,ref(reactorc));  //用于测试reactorc.Stop

    reactorc.Start();

    

    return 0;
}